import React, {Component} from 'react'
import ReactDOM from 'react-dom'

class App extends Component{
    state = {
        count: 0
    }

    onIncrement(){
        // 使用setState函数才能修改初始化的state
        this.setState({
            count: this.state.count + 1
        })
    }

    render() {
        return (
            <div>
                <h1>计算机：{ this.state.count }</h1>
                {/* =>函数绑定的不是本this，而是外面一层对象，这样就实现+1操作 */}
                <button onClick={()=>this.onIncrement()}>+1·</button>
            </div>
        )
    }
}

ReactDOM.render(<App/>, document.getElementById('root'))